/**
 * Created by WU on 2016/9/24.
 */
var DBPool=require('../util/DBpool');
module.exports= {
    pic:function (usertel,callback){
        var sql="select * from t_userinfo where tel=?";
        DBPool.getConnection(function (client) {
                client.query(sql,[usertel],function (error,result) {
                    if(error){
                        console.log(error.message);
                        return;
                    }
                    callback(result);
                    client.release();
                });
            });
    },
    get_article:function (username,callback){
        var sql="select artno,icon,title,date,content from t_article where t_article.userno=(select t_userinfo.userno from t_userinfo where username=?)";
        DBPool.getConnection(function (client) {
            client.query(sql,[username],function (error,result) {
                if(error){
                    console.log(error.message);
                    return;
                }
                callback(result);
                client.release();
            });
        });
    },
    delete_article:function (artno,callback){
        var sql="delete from t_article where artno=?;";
        DBPool.getConnection(function (client) {
            client.query(sql,[artno],function (error,result) {
                if(error){
                    console.log(error.message);
                    return;
                }
                console.log('????????????????');
                callback(result);
                client.release();
            });
        });
    },

    update:function (userno,callback){
        var sql="delete from t_article where artno=?;";
        DBPool.getConnection(function (client) {
            client.query(sql,[artno],function (error,result) {
                if(error){
                    console.log(error.message);
                    return;
                }
                callback(result);
                client.release();
            });
        });
    },

    update_user:function(username,usersex,userbirth,useremail,qq,useraddress,userno,callback){
        var sql="UPDATE t_userinfo SET username=?,usersex=?,userbirth=?,useremail=?,qq=?,useraddress=? where  userno=?";
        DBPool.getConnection(function (client) {
            client.query(sql,[username,usersex,userbirth,useremail,qq,useraddress,userno],function (error,result) {
                if(error){
                    console.log(error.message);
                    return;
                }
                callback(result);
                client.release();
            });
        });
    },

    get_usertype:function(userno,callback){
        var sql="select usertype from t_userinfo where userno=?";
        DBPool.getConnection(function (client) {
            client.query(sql,[userno],function (error,result) {
                if(error){
                    console.log(error.message);
                    return;
                }
                callback(result);
                client.release();
            });
        });
    },
    update_icon:function(name,tel,callback){
        var sql="update t_userinfo set pic=? where tel=? ";
        DBPool.getConnection(function (client) {
            client.query(sql,[name,tel],function (error,result) {
                if(error){
                    console.log(error.message);
                    return;
                }
                callback(result);
                client.release();
            });
        });

    }




};
